from datetime import datetime

from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.

# 性别选择
GENDER_CHOICES = (
    ("male", "男"),
    ("female", "女"),

)


class BaseModel(models.Model):
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        abstract = True


# 用户信息表 - 继承 django 提供的默认用户表
class UserProfile(AbstractUser):
    # 昵称
    nick_name = models.CharField(verbose_name="昵称", max_length=50, default="")
    # 生日
    birthday = models.DateField(verbose_name="生日", null=True, blank=True)
    # 性别
    gender = models.CharField(verbose_name="性别", max_length=6, choices=GENDER_CHOICES)
    # 地址
    address = models.CharField(verbose_name="地址", max_length=100, default="")
    # 头像
    avatar = models.ImageField(verbose_name="头像", upload_to="avatar/users/%Y/%m",
                               default="avatar/default/default_avatar.png")

    # 配置信息
    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        if self.nick_name:
            return self.nick_name
        else:
            return self.username
